/**************************************
This program estimates regressions for our
sandwich estimator, which is discussed briefly in the paper

These estimates are not disclosed, but the program can be

Author: Andrew Foote
Date: 02/04/2019

Updated: 12/28/2022; adding time stamp to postfile
**************************************/
#delimit ;
set more off; 

include "./config.do" ;

use "$datadir/sandwich_earnings_test.dta", clear; 

des;

tab year_grad;  

/*************************************
First, keep only people
who aren't missing demographics.
*************************************/


include "./restrictions.do" ;

include "./top_school.do" ;

tab opeid top_school, m ;
 
tab ui_state top_school, m ; 
/*********************************************************
Going to run a number of regressions (controlling for 
demographics) 

Outcomes: 

Total Earnings
Total Earnings > 0
Log Earnings
p25 log
p50 log
p75 log
**********************************************************/  

local demogs "male white hispanic black asian inst_state*" ;


postfile support spec str15 comment str20 category double Nobs share_topschool double count_top double count_nottop beta se 
                                using $supportdir/support_regs_sandwich_$date.dta, replace;

reg national_earnings top_school i.year i.year_grad  if year > year_grad , cluster(pik) ;

reg instate_earnings top_school i.year i.year_grad `demogs' if year > year_grad & (instate_earnings > 0 | national_earnings == 0), cluster(pik) ;

/**************** With demographics ************************/

foreach category in national national_sandwich instate instate_sandwich  { ;

	reg `category'_earnings top_school i.year i.year_grad i.quarter `demogs' if year > year_grad , cluster(pik) ;
              local beta2_`category'_1 = _b[top_school];
              local se2_`category'_1 = _se[top_school] ;
              local N2_`category'_1 =  e(N) ;

               sum top_school if e(sample) ;
               local share_top = r(mean) ;
               count if top_school == 1 & e(sample) ;
               local count_top = r(N) ;
               count if top_school ==0 & e(sample) ;
               local count_nottop= r(N) ;
               post support (1) ("Controls") ("`category'") (e(N)) (`share_top') (`count_top') (`count_nottop') (_b[top_school]) (_se[top_school]);

	reg `category'_earnings top_school i.year i.year_grad i.quarter  `demogs' if year>year_grad  & `category'_earnings>0, cluster(pik) ;               
              local beta2_`category'_2 = _b[top_school];
              local se2_`category'_2 = _se[top_school] ;
              local N2_`category'_2 =  e(N) ;

              sum top_school if e(sample) ;
               local share_top = r(mean) ;
               count if top_school == 1 & e(sample) ;
               local count_top = r(N) ;
               count if top_school ==0 & e(sample) ;
               local count_nottop= r(N) ;
               post support (2) ("Controls") ("`category'") (e(N)) (`share_top') (`count_top') (`count_nottop') (_b[top_school]) (_se[top_school]);                         
	
	reg log_earn_`category' top_school i.year i.year_grad i.quarter `demogs' if year>year_grad  & `category'_earnings>0, vce(cluster pik) ;
              local beta2_`category'_3 = _b[top_school];
              local se2_`category'_3 = _se[top_school] ;
              local N2_`category'_3 =  e(N) ;

              sum top_school if e(sample) ;
               local share_top = r(mean) ;
               count if top_school == 1 & e(sample) ;
               local count_top = r(N) ;
               count if top_school ==0 & e(sample) ;
               local count_nottop= r(N) ;
               post support (3) ("Controls") ("`category'") (e(N)) (`share_top') (`count_top') (`count_nottop') (_b[top_school]) (_se[top_school]);                         
	
} ;



postclose support ; 


                                    
